home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / BORL_TIP / TI100 / TI670.ASC < prev    next >
Text File  |  1994-10-03  |  6KB  |  283 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Pascal                                 NUMBER  :  670
  8.   VERSION  :  All
  9.        OS  :  DOS
  10.      DATE  :  September 30, 1994                       PAGE  :  1/5
  11.  
  12.     TITLE  :  Messaging Between Two Dialogs/Update Backgroung
  13.  
  14.  
  15.  
  16.  
  17.  
  18. {
  19.    This program will create two modeless dialog boxes and will
  20.    allow only one dialog to be created at any time.
  21.  
  22.    Additionally, it demonstrates how to broadcast messages to
  23.    background windows and update information without changing
  24.    the selected dialog.
  25.  
  26. }
  27. {$X+}
  28.  
  29. Program DialogCommunication;
  30.  
  31. uses Objects, Drivers, Views, Menus, Dialogs, App, Crt;
  32. const
  33.   cmDialog1 = 100;
  34.   cmDialog2 = 101;
  35.   cmDialog1Button = 200;
  36.   cmDialog2Button = 201;
  37.  
  38. type
  39.  
  40.  PHelloApp = ^THelloApp;
  41.   THelloApp = object(TApplication)
  42.     procedure MakeDialog;
  43.     procedure HandleEvent(var Event: TEvent); virtual;
  44.     procedure InitMenuBar; virtual;
  45.     procedure InitStatusLine; virtual;
  46.   end;
  47.  
  48.   PMyDialog1 = ^TMyDialog1;
  49.   TMyDialog1 = object(TDialog)
  50.     procedure MakeDialog2;
  51.     procedure HandleEvent(var Event:TEvent); virtual;
  52.   end;
  53.  
  54.   PMyDialog2 = ^TMyDialog2;
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.   PRODUCT  :  Pascal                                 NUMBER  :  670
  68.   VERSION  :  All
  69.        OS  :  DOS
  70.      DATE  :  September 30, 1994                       PAGE  :  2/5
  71.  
  72.     TITLE  :  Messaging Between Two Dialogs/Update Backgroung
  73.  
  74.  
  75.  
  76.  
  77.   TMyDialog2 = object(TMyDialog1)
  78.     procedure HandleEvent(var Event:TEvent); virtual;
  79.   end;
  80.  
  81. procedure TMyDialog1.HandleEvent(var Event: TEvent);
  82. var
  83.   AreYouThere: PView;
  84. begin
  85.   TDialog.HandleEvent(Event);
  86.   if Event.What = evCommand then
  87.     begin
  88.       case Event.Command of
  89.          cmDialog1Button:
  90.            begin
  91.              AreYouThere:= Message(DeskTop, evBroadcast,
  92. cmDialog2, nil);
  93.              if AreYouThere = nil then
  94.                 MakeDialog2
  95.               else
  96.                 ClearEvent(Event);
  97.            end
  98.       else
  99.         Exit;
  100.       end;
  101.         ClearEvent(Event);
  102.     end;
  103. end;
  104.  
  105. procedure TMyDialog1.MakeDialog2;
  106. var
  107.   Dialog2: PMyDialog2;
  108.   R: TRect;
  109.   Button: PButton;
  110. begin
  111.   R.Assign(1,1,40,20);
  112.   Dialog2:= New(PMyDialog2, init(R,'Dialog2'));
  113.   R.Assign(10,10,20,12);
  114.   Button:= New(PButton,Init(R,'Beep', cmDialog2Button,
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.   PRODUCT  :  Pascal                                 NUMBER  :  670
  128.   VERSION  :  All
  129.        OS  :  DOS
  130.      DATE  :  September 30, 1994                       PAGE  :  3/5
  131.  
  132.     TITLE  :  Messaging Between Two Dialogs/Update Backgroung
  133.  
  134.  
  135.  
  136.  
  137. bfdefault));
  138.   Dialog2^.Insert(Button);
  139.   DeskTop^.Insert(Dialog2);
  140. end;
  141.  
  142. procedure TMyDialog2.HandleEvent(var Event: TEvent);
  143. begin
  144.   case Event.Command of
  145.     cmDialog2: begin
  146.                  sound(2000); delay(10); nosound;
  147.                  Title:=newstr('Hello world');
  148.                  ReDraw;
  149.                  ClearEvent(Event);
  150.                end;
  151.   end;
  152.   TDialog.HandleEvent(Event);
  153.   if Event.What = evCommand then
  154.     begin
  155.       case Event.Command of
  156.          cmDialog2Button: begin
  157.                             Sound(1000); delay(100); NoSound;
  158.                           end;
  159.       else
  160.         Exit;
  161.       end;
  162.         ClearEvent(Event);
  163.     end;
  164. end;
  165.  
  166. { THelloApp }
  167.  
  168. procedure THelloApp.MakeDialog;
  169. var
  170.   R:TRect;
  171.   Button1: PButton;
  172.   Dialog1: PMyDialog1;
  173. begin
  174.   R.Assign(25, 5, 65, 16);
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.   PRODUCT  :  Pascal                                 NUMBER  :  670
  188.   VERSION  :  All
  189.        OS  :  DOS
  190.      DATE  :  September 30, 1994                       PAGE  :  4/5
  191.  
  192.     TITLE  :  Messaging Between Two Dialogs/Update Backgroung
  193.  
  194.  
  195.  
  196.  
  197.   Dialog1:= New(PMyDialog1, init(R,'Dialog1'));
  198.   R.Assign(16, 8, 38, 10);
  199.   Button1:= New(PButton, Init(R,'Call Dialog2', cmDialog1Button,
  200. bfDefault));
  201.   Dialog1^.Insert(Button1);
  202.   DeskTop^.Insert(Dialog1);
  203. end;
  204.  
  205. procedure THelloApp.HandleEvent(var Event: TEvent);
  206. begin
  207.   TApplication.HandleEvent(Event);
  208.   if Event.What = evCommand then
  209.     begin
  210.       case Event.Command of
  211.          cmDialog1:begin
  212.                      MakeDialog;
  213.                    end;
  214.       else
  215.         Exit;
  216.       end;
  217.         ClearEvent(Event);
  218.      end;
  219. end;
  220.  
  221. procedure THelloApp.InitMenuBar;
  222. var
  223.   R: TRect;
  224. begin
  225.   GetExtent(R);
  226.   R.B.Y := R.A.Y + 1;
  227.   MenuBar := New(PMenuBar, Init(R, NewMenu(
  228.     NewSubMenu('~O~pen Dialogs', hcNoContext, NewMenu(
  229.       NewItem('~D~ialog1','', 0, cmDialog1, hcNoContext,
  230.       NewLine(
  231.       NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit,
  232.         hcNoContext, nil)))), nil))));
  233. end;
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.   PRODUCT  :  Pascal                                 NUMBER  :  670
  248.   VERSION  :  All
  249.        OS  :  DOS
  250.      DATE  :  September 30, 1994                       PAGE  :  5/5
  251.  
  252.     TITLE  :  Messaging Between Two Dialogs/Update Backgroung
  253.  
  254.  
  255.  
  256.  
  257. procedure THelloApp.InitStatusLine;
  258. var
  259.   R: TRect;
  260. begin
  261.   GetExtent(R);
  262.   R.A.Y := R.B.Y-1;
  263.   StatusLine := New(PStatusLine, Init(R,
  264.     NewStatusDef(0, $FFFF,
  265.       NewStatusKey('', kbF10, cmMenu,
  266.       NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit, nil)), nil)));
  267. end;
  268.  
  269. var
  270.   HelloWorld: THelloApp;
  271.  
  272. begin
  273.   HelloWorld.Init;
  274.   HelloWorld.Run;
  275.   HelloWorld.Done;
  276. end.
  277.  
  278.  
  279. DISCLAIMER: You have the right to use this technical information
  280. subject to the terms of the No-Nonsense License Statement that
  281. you received with the Borland product to which this information
  282. pertains.
  283.